
var map = new AMap.Map('allmap', {
    resizeEnable: true,
    zoom: 10
});
AMap.plugin('AMap.Geolocation', function() {
    var marker = new AMap.Marker({
        icon: "https://webapi.amap.com/theme/v1.3/markers/n/mark_b.png",
    });
    var geolocation = new AMap.Geolocation({
        enableHighAccuracy: true,//是否使用高精度定位，默认:true
        timeout: 10000,          //超过10秒后停止定位，默认：5s
        buttonPosition:'LB',    //定位按钮的停靠位置
        buttonOffset: new AMap.Pixel(10, 20),//定位按钮与设置的停靠位置的偏移量，默认：Pixel(10, 20)
        // zoomToAccuracy: true,   //定位成功后是否自动调整地图视野到定位点
        markerOptions:marker

    });
    map.addControl(geolocation);
    geolocation.getCurrentPosition(function(status,result){
        if(status=='complete'){
            // onComplete(result)
        }
    });
});
mui.ajax('/admin/position',{
    data:{
        latitude:0,
        longitude: 0
    },
    type:'post',//HTTP请求类型
    success:function(data){
        console.log(data);
        var pointerList = data;
        var icon = new AMap.Icon({
            image: '/images/ditu.jpg',
            size: new AMap.Size(30, 30),
            imageSize:new AMap.Size(30, 30)
        });
        for (var i = 0; i < pointerList.length; i ++) {
            var m = new AMap.Marker({
                position: [pointerList[i].longitude, pointerList[i].latitude],
                icon: icon,
                size: new AMap.Size(30, 30),
                extData:pointerList[i].id
            });
            // m.on("click",toDetail(pointerList[i].id));
            AMap.event.addListener(m, 'click', function(e){
                location.href = '/shopInfo?id=' +e.target.getExtData();
            });
            // var markerPoint = new BMap.Point(pointerList[i].longitude, pointerList[i].latitude);
            // var id = pointerList[i].id;
            // addMarker(markerPoint, id);
            map.add(m);
        }
    },
    error:function(data){
        console.log('data',data);
    }
});
//解析定位结果
function onComplete(data) {
    var x=data.position.lat;
    var y=data.position.lng
    console.log(data.position.lat);
    console.log(data.position.lng);


}
//解析定位错误信息
function onError(data) {
    document.getElementById('status').innerHTML='定位失败'
    document.getElementById('result').innerHTML = '失败原因排查信息:'+data.message;
}